#include <stdio.h>
#include <string.h>
#include <history.h>
#include <turtle.h>

int main(int argc, char *argv[])
{
	HISTORY h[MAX_HISTORY];
	TURTLE t[MAX_HISTORY];
	unsigned short n;
	int i;
	FILE *output;

	if(argc<2)
		return -1;

	memset(h, 0, sizeof(h));
	if( GetHistory(argv[1], h, &n) < 0 )
		return -1;

	if( DoTurtle(h, t, n) < 0 )
		return -1;

	if( (output=fopen(argv[1], "w")) != NULL )
	{
		fprintf(output, "日期\t開盤\t最高\t最低\t收盤"
				"\tTR\tATR\tBK\n");

		for(i=0; i<n; i++)
			fprintf(output,
				"%4d/%02d/%02d"
				"\t%.2lf\t%.2lf\t%.2lf\t%.2lf"
				"\t%.2lf\t%.2lf"
				//"\t%d"
				//"\t%d"
				"\t%.2lf"
				"\t%.2lf"
				"\n"
				, h[i].year, h[i].month, h[i].day
				, h[i].open, h[i].high, h[i].low, h[i].close
				, t[i].tr, t[i].atr
				//, t[i].breakout.high[65]
				//, t[i].breakout.low[65]
				, t[i].breakout.high[65]==0xFFFF?0:h[t[i].breakout.high[65]].close
				, t[i].breakout.low[65]==0xFFFF?0:h[t[i].breakout.low[65]].close
				);
		fclose(output);
	}

	
	
	
	
	
	
	
	










	return 0;
}




